{layout name="layout"}
<link href="__CSS__/admin.css" rel="stylesheet">
<script src="__PLU__/bootbox/bootbox.min.js"></script>
<div class="panel">
    <div class="panel-body">
        <div class="pad-btm form-inline">
            <div class="row">
                <div class="col-sm-6 table-toolbar-left">
                    <button id="group-btn-addrow" data-target="#groups-modal" data-toggle="modal" class="btn btn-default"><i class="fa fa-plus-circle"></i> 添加</button>
                </div>
            </div>
        </div>
        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>组名</th>
                        <th>组类型</th>
                        <th>是否启用</th>
                        <th>用户数</th>
                        <th>更新时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {if $groups}
                        {foreach $groups as $group}
                        <tr>
                            <td class="text-center pad-itop">{$group.name}</td>
                            <td class="text-center pad-itop">{$group.type}</td>
                            <td class="text-center pad-itop">{$group.is_use}</td>
                            <td class="text-center pad-itop">{$group.count}</td>
                            <td class="text-center pad-itop">{$group.last_modify}</td>
                            <td class="text-center">
                                <div class="btn-group">
                                    <button class="btn btn-default" data-target="#groups-modal" data-toggle="modal" data-groupid="{$group.group_id}"><i class="fa fa-pencil-square-o"></i></button>
                                    <button class="btn btn-default" onclick='del_group(this,"{$group.group_id}")'><i class="ion-trash-b"></i></button>
                                </div>
                            </td>
                        </tr>
                        {/foreach}
                    {else}
                    <tr>
                        <td colspan="5" class="text-center">还未添加分组</td>
                    </tr>
                    {/if}
                </tbody>
            </table>
        </div>
    </div>
</div>
{include file="modals/groups-modal"}
<script type="text/javascript">
    function del_group(e,groupid){
        bootbox.setDefaults({locale:"zh_CN"});
        bootbox.confirm("确定删除吗", function(result) {
            if(result){
                $.ajax({
                    url:"{:url('admin/groups/del_group')}",
                    type:"post",
                    data:{"groupid":groupid},
                    dataType:"json",
                    success:function(result){
                        if(result.status == 'success'){
                            $.niftyNoty({
                                type: 'success',
                                icon : 'pli-exclamation icon-2x',
                                message : result.msg,
                                container : 'floating',
                                timer : 1500,
                            });
                            $(e).parents('.category-div').detach();
                        }else{
                            $.niftyNoty({
                                type: 'warning',
                                icon : 'pli-exclamation icon-2x',
                                message : result.msg,
                                container : 'floating',
                                timer : 1500,
                            });
                        }
                    },
                    error:function(){
                        $.niftyNoty({
                            type: 'danger',
                            icon : 'pli-exclamation icon-2x',
                            message : '网络连接失败',
                            container : 'floating',
                            timer : 1500,
                        });
                    }
                });
            }
        })
    }
</script>